def canPlaceFlowers(flowerbed, n):
    count = 0  # 可以种植花的数量
    length = len(flowerbed)
    
    for i in range(length):
        if flowerbed[i] == 0:
            # 检查左右是否为空或者边界
            left_empty = (i == 0) or (flowerbed[i - 1] == 0)
            right_empty = (i == length - 1) or (flowerbed[i + 1] == 0)
            
            if left_empty and right_empty:
                flowerbed[i] = 1  # 种花
                count += 1
                if count >= n:
                    return True  # 提前返回，节省时间

    return count >= n


# 测试用例
if __name__ == "__main__":
    test_cases = [
        ([1, 0, 0, 0, 1], 1, True),
        ([1, 0, 0, 0, 1], 2, False),
        ([1, 0, 0, 0, 0, 0, 1], 2, True),
        ([0, 0, 0], 2, False),
        ([0, 0, 0], 1, True),
        ([1, 0, 1, 0, 1, 0, 1], 0, True),
        ([], 0, True),
        ([0], 1, True),
        ([1], 1, False),
    ]
    
    for i, (flowerbed, n, expected) in enumerate(test_cases):
        result = canPlaceFlowers(flowerbed.copy(), n)
        print(f"测试用例 {i+1}: 花坛={flowerbed}, n={n} => {'通过' if result == expected else '失败'}")